package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Spannable;
import android.text.Spanned;
import android.text.format.DateUtils;
import android.text.method.ScrollingMovementMethod;
import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,View.OnLongClickListener {
private  TextView tv_bbs;
private  TextView tv_control;
private  TextView super_text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         tv_control = (TextView) findViewById(R.id.tv_control);
         tv_control.setOnClickListener(this);
         tv_control.setOnLongClickListener(this);


        tv_bbs = (TextView) findViewById(R.id.tv_bbs);
        tv_bbs.setOnClickListener(this);
        tv_bbs.setOnLongClickListener(this);

        tv_bbs.setGravity(Gravity.LEFT|Gravity.BOTTOM);
        tv_bbs.setLines(8);
        tv_bbs.setMaxLines(8);
        tv_bbs.setMovementMethod(new ScrollingMovementMethod());
        ///超链接
        super_text = (TextView) findViewById(R.id.super_text);
        Spannable s = (Spannable)super_text.getText();
        StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
        s.setSpan(boldSpan,0,8, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);///0-8字节
    }

    private String[] mChatStr = {"快速开发", "富有表现力和灵活的UI","热重载", "动画/运动API","访问本地功能和SDK", "访问本地功能和SDK","为您的用户带来全新体验。", "为您的用户带来全新体验。",};

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.tv_control||v.getId() == R.id.tv_bbs){
            int random = (int)(Math.random()*10)%5;
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
            Date date = new Date(System.currentTimeMillis());
            String newString = String.format("%s\n%s%s",tv_bbs.getText().toString(),date.clone(),mChatStr[random]);
            tv_bbs.setText(newString);
        }
    }

    @Override
    public boolean onLongClick(View v) {
        if(v.getId() == R.id.tv_control||v.getId() == R.id.tv_bbs){
            tv_bbs.setText("");
        }
        return true;
    }
}
